<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Page-Enter" Content="revealTrans(duration=1.5, transition=19)">
<meta http-equiv="Page-Exit" Content="revealTrans(duration=1.5, transition=19)">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-touch-fullscreen" content="YES" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>支付</title>
</head>
<body>
<script type="text/javascript">
function onBridgeReady() {
    WeixinJSBridge.invoke('getBrandWCPayRequest', {
        "appId": "<?=$this->pay['appId'];?>",
        "timeStamp": "<?=$this->pay['timeStamp'];?>",
        "nonceStr": "<?=$this->pay['nonceStr'];?>",   
        "package": "<?=$this->pay['package'];?>",
        "signType": "<?=$this->pay['signType'];?>", 
        "paySign": "<?=$this->pay['paySign'];?>"
    }, function(res) {
        //支付成功 
        if (res.err_msg == "get_brand_wcpay_request:ok") {
            window.location.href = '/cashier/paycallback?trade_type=JSAPI&pay_order_id=<?=$this->pay['pay_order_id'];?>';
        }
        //支付失败或支付取消
        else if (res.err_msg == "get_brand_wcpay_request:fail" || res.err_msg == "get_brand_wcpay_request:cancel") {
            window.location.href = '/cashier/paycallback?trade_type=JSAPI&pay_order_id=<?=$this->pay['pay_order_id'];?>';
        }        
    });
}

function callPay() {
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
}
//自动弹出支付
callPay();
</script>
</body>
</html>